﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.AvalonEdit.CodeCompletion;

namespace SmallProgram
{
    public class ProgramCompletionData : ICompletionData
    {
        public void Complete(ICSharpCode.AvalonEdit.Editing.TextArea textArea, ICSharpCode.AvalonEdit.Document.ISegment completionSegment, EventArgs insertionRequestEventArgs)
        {
            string editingWord = textArea.Document.Text.Substring(completionSegment.Offset, completionSegment.Length);
            int startIndex = completionSegment.Offset;
            while ((--startIndex > 0) && (char.IsLetterOrDigit(textArea.Document.Text[startIndex])))
            {
                editingWord = textArea.Document.Text[startIndex] + editingWord;
            }
            textArea.Document.Replace(startIndex+1, editingWord.Length, this.Text);
        }

        public object Content
        {
            get
            {
                return Text;
            }            
        }

        public object Description
        {
            get;
            set;
        }

        public System.Windows.Media.ImageSource Image
        {
            get;
            set;
        }

        public double Priority
        {
            get;
            set;
        }

        public string Text
        {
            get;
            set;
        }
    }
}
